var isHappy = function(n) {
    let ans = new Map()
    while(true){
        if(n===1) return true
        if(ans.has(n)) return false
        ans.set(n,1)
        // console.log(n);
        n=tools(n)
    }

    function tools(num){
        let k=0;
        while(num>0){
            k=(num%10)*(num%10)+k
            num=Math.floor(num/10)
            
        }
       return k
    }
};

console.log(isHappy(19));


